package graph;

import list.*;

public class Vertex {
	int degree;
	DList edgeList;
	Object vertexObject;
	DListNode myNode;
	
	protected Vertex(Object obj) {
		edgeList = new DList();
		vertexObject = obj;
		
	}
	
	/** addEdge() adds an edge to be documented on this vertex object so that 
	 *  the edge will be recorded accurately in the adjacency list.
	 *  return true if added successfully, false otherwise.
	 *  @param e is the edge we are adding onto this vertex's edgeList. 
	 *  IMPORTANT NOTE: this method assumes the edge e is a valid one (i.e. that 
	 *  both vertexes listed in the edge actually exist and that it doesn't conflict
	 *  with a copy of an existing edge).
	 *  
	 *  Running time: O(1)
	 */
	protected void addEdge(Edge e) {
		edgeList.insertBack(e); 
		degree++;
	}
	
	/** 
	 * removeMe() removes this vertex from it's associated DList (which is the WUGraph's 
	 * vertexList field).
	 * 
	 * Running time: O(1)
	 */
	protected void removeMe() {
		try {
			myNode.remove();
		} catch (InvalidNodeException e) {
			Thread.dumpStack();
		}
	}
	
	/** 
	 * toString() represents a String representation of this vertex.
	 * @return a string that represents it's application version of the vertex object
	 *  (it's toString()) and the degree of this vertex in the graph.
	 */
	public String toString() {
		String s = "";
		s = s + "[ " + vertexObject.toString() + " , " + " degree: " + degree + " ]";
		return s;
	}
}
